/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.imagelinkfixer;

import cz.mzk.kramerius.commons.DatastreamId;
import cz.mzk.kramerius.commons.Dom4jUtils;
import cz.mzk.kramerius.fedoraaccess.FedoraConnector;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.XPath;

/**
 *
 * @author rehan
 */
public class AbstractFixer {

    final FedoraConnector conn;

    public AbstractFixer(FedoraConnector conn) {
        this.conn = conn;
    }

    List<String> getPidsOfPages(String monographPid) {
        Document relsExtDoc = conn.getXmlDatastreamDissemination(monographPid, DatastreamId.RELS_EXT);
        //System.out.println(relsExtDoc.asXML());
        XPath path = Dom4jUtils.createXPath("//kramerius:hasPage/@rdf:resource");
        List<Node> nodes = path.selectNodes(relsExtDoc);
        List<String> result = new ArrayList<String>(nodes.size());
        for (Node node : nodes) {
            String pid = node.getText().substring("info:fedora/".length());
            result.add(pid);
        }
        return result;
    }
}
